const express =require('express')
require('./db/index')//引入数据库
const path = require('path')


const app =express()
const addAdminRoute =require('./routes/addAdmin')
const adminListRoute =require('./routes/adminList')
const deleteAdminRoute =require('./routes/deleteAdmin')
const loginRoute = require("./routes/login")
const isLogin = require("./routes/isLogin")
const addAdvRoute = require("./routes/addAdv")
const advListRoute = require("./routes/advList")
const deleteAdvRoute = require("./routes/deleteAdv")
const updateGetDataRoute = require("./routes/updateGetData")

//处理post请求的中间件，会在req添加一个body属性
app.use(express.urlencoded())
app.use(express.json())
//暴露静态资源中间件
app.use('/upload',express.static(path.resolve(__dirname,'./upload')))//第一个参数是限制路径是/upload时，才能找到这里的文件


//使用路由
app.use(addAdminRoute)
app.use(adminListRoute)
app.use(deleteAdminRoute)
app.use(loginRoute);
app.use(isLogin)
app.use(addAdvRoute)
app.use(advListRoute)
app.use(deleteAdvRoute)
app.use(updateGetDataRoute)


app.listen(8000,()=>{
    console.log('启动服务器成功')
})